package tk.mybatis.web.model;

import org.apache.commons.lang.time.DateUtils;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

public class Person {
    private Integer id;
    private String name;
    private Integer age;
    private Date birthday;

    public Integer getId() {
        return id;
    }

    public void setId(Integer id) {
        this.id = id;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public Integer getAge() {
        return age;
    }

    public void setAge(Integer age) {
        this.age = age;
    }

    public Date getBirthday() {
        return birthday;
    }

    public void setBirthday(Date birthday) {
        this.birthday = birthday;
    }

    public String getBirthdayString() {
        if (birthday != null) {
            return new SimpleDateFormat("yyyy-MM-dd").format(birthday);
        }
        return "";
    }

    public void setBirthdayString(String time) {
        try {
            this.birthday = DateUtils.parseDate(time, new String[]{"yyyy-MM-dd"});
        } catch (ParseException e) {
            throw new RuntimeException(e);
        }
    }

}
